package com.nameless.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nameless.dao.BaseAreaDao;
import com.nameless.dao.BrandDao;
import com.nameless.dao.ShopDao;
import com.nameless.entity.BaseArea;
import com.nameless.entity.Brand;
import com.nameless.entity.Shop;
import com.nameless.service.BrandService;
import com.nameless.service.ShopService;
import com.nameless.vo.Result;
import com.nameless.vo.ShopVo;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @author keluoyisi
 * @program: car-parent
 * @description:
 * @date 2023-02-27 17:24:49
 */
@Service
@SuppressWarnings("all")
public class ShopServiceImpl extends ServiceImpl<ShopDao, Shop> implements ShopService {

    @Autowired
    private ShopDao shopDao;

    @Autowired
    private BaseAreaDao baseAreaDao;
    @Override
    public Result queryAllByParam(ShopVo shopVo) {
        PageHelper.startPage(shopVo.getPageNum(),shopVo.getPageSize());
        QueryWrapper<Shop> wrapper = new QueryWrapper<>();
        if (shopVo.getName()!=null){
            wrapper.like("name",shopVo.getName());
        }
        if (shopVo.getAddress()!=null){
            wrapper.like("address",shopVo.getAddress());
        }
        List<Shop> shops = shopDao.selectList(wrapper);
        PageInfo<Shop> info = new PageInfo<>(shops);
        return new Result(200,"成功",info);
    }

    @Override
    public Result insertShop(Shop shop) {
        int insert = shopDao.insert(shop);
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String format = formatter.format(date);

        shop.setAddtime(format);
        return new Result(200,"成功");
    }

    @Override
    public Result updateShop(Shop shop) {
        int i = shopDao.updateById(shop);
        return new Result(200,"成功");
    }

    @Override
    public Result deleteById(Integer id) {
        int i = shopDao.deleteById(id);
        return new Result(200,"成功");
    }

    @Override
    public List<Shop> selectShopAll() {
        List<Shop> shops = shopDao.selectList(null);
        return shops;
    }

    @Override
    public Result areaIdShop(Integer areaId) {
//        QueryWrapper<BaseArea> wrapper1 = new QueryWrapper<>();
//        wrapper1.eq("name",name);
//        BaseArea baseArea = baseAreaDao.selectOne(wrapper1);
        QueryWrapper<Shop> wrapper = new QueryWrapper<>();
        wrapper.eq("area_id",areaId);
        List<Shop> shops = shopDao.selectList(wrapper);

        return new Result(200,"成功",shops);
    }
}
